package org.biloxi.model.player.impl;

import java.util.List;

import org.biloxi.model.magicobjects.MagicObject;
import org.biloxi.model.mutable.player.PlayerStateMutable;
import org.biloxi.model.mutable.player.ZoneMutable;
import org.biloxi.model.player.Zone;
import org.biloxi.player.PlayerID;

public class PlayerStateImpl implements PlayerStateMutable {

	private final PlayerID _playerid;
	private final ZoneMutable _graveYard ;
	private final ZoneMutable _hand      ;
	private final ZoneMutable _inPlay    ;
	private final ZoneMutable _library   ;
	private int _lives = 20;
	private boolean _isLost = false;
	
	public boolean hasLost() {
		return _isLost;
	}

	public void setIsLost(boolean lost) {
		_isLost = lost;
	}

	/**
	 * Creates a PlayerState in an initial state with a given player id and 
	 * Deck of cards for an initial library. 
	 * @param
	 */
	public PlayerStateImpl(PlayerID pid, List<MagicObject> d) {
		_playerid = pid;
		_graveYard = new ZoneImpl(pid);
		_hand      = new ZoneImpl(pid);
		_inPlay    = new ZoneImpl(pid);
		_library   = new ZoneImpl(pid);
		for(MagicObject card : d)
			_library.mutableMagicObjects().add(0, card);
	}

	public PlayerID getPlayerID() {
		return _playerid;
	}
	
	/**
	 * Gets cards in hand.
	 * @return
	 */
	public Zone getHand(){
		return _hand;
	}
	
	/**
	 * Gets cards in-play.
	 * @return
	 */
	public Zone getInPlay(){
		return _inPlay;
	}
	
	/**
	 * Gets cards in library.
	 * @return
	 */
	public Zone getLibrary(){
		return _library;
	}
	
	/**
	 * Returns lives remaining for player.
	 * @return
	 */
	public int getLives(){
		return _lives;
	}

	/**
	 * Gets cards in graveyard.
	 * @return
	 */
	public Zone getGraveYard() {
		return _graveYard;
	}

	public ZoneMutable mutableGraveYard() {
		return _graveYard;
	}

	public ZoneMutable mutableHand() {
		return _hand;
	}

	public ZoneMutable mutableInPlay() {
		return _inPlay;
	}

	public ZoneMutable mutableLibrary() {
		return _library;
	}

	public void setHasLost(boolean loser) {
		_isLost = loser;
	}

	public void setLives(int lives) {
		_lives = lives;
	}
	
	
}
